package com.kanche.bigbaby.notused;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import com.kanche.bigbaby.R;
import com.kanche.bigbaby.support.base.BasePage;
import com.kanche.bigbaby.support.listview.PullLoadListView;
import com.kanche.bigbaby.support.listview.SampleAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Chenshao_Young on 15/5/18.
 */
public class ListViewPage extends BasePage implements PullLoadListView.IPullLoadListener{

    PullLoadListView mRecyclerView;
    String pageTitle;
    int pageId;
    private SampleAdapter adapter;

    public ListViewPage(Context context,String pageTitle) {
        super(context);

        this.pageTitle = pageTitle;
//        this.pageId = pageId;
    }

    @Override
    protected View initView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.page_listview,null);

        mRecyclerView = justFindIt(view,android.R.id.list);


        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setLoadListener(this);
        adapter = new SampleAdapter();
        mRecyclerView.setAdapter(adapter);

            addList();
        return view;
    }


    private void addList() {
        List<Integer> list = getList();
        adapter.getList().addAll(list);
        adapter.notifyDataSetChanged();
    }

    private List<Integer> getList() {
        List<Integer> list = new ArrayList<Integer>();
        int size = adapter.getList().size();
        int lastPosition = size > 0 ? adapter.getList().get(size - 1) : 0;
        for (int i = 1; i < 20; i++) {
            list.add(lastPosition + i);
        }

        return list;
    }
    @Override
    public void onClick(View v) {

    }

    @Override
    public void loadMore() {
        addList();
    }
}
